<?php 
include("../../conexion.php");

$sql =mysql_query("SELECT * FROM m_cteventas",$conn) or die(mysql_error());

$evalbus      = $_REQUEST["evalbus"];
$codigo_cli   = $_REQUEST["codigo_cli"];
$tipo_docu    = $_REQUEST["tipo_docu"];
$serie        = $_REQUEST["serie"];
$documento    = $_REQUEST["documento"];

?>
<script type="text/javascript" src="../includes/Mantenimientos.js"></script> 
<style type="text/css">
<!--
.titubuskar {
	font-family: Calibri;
	font-size: 12px;
	font-weight: bold;
	font-style: italic;
	color: #003366;
}
.titubuskar0 {font-family: Calibri; font-size: 12px; font-style: italic; font-weight: bold; color: #333333; }
.titubuskar1 {color: #333333}
.reskar2 {font-family: Calibri; font-size: 13px; font-weight: bold; font-style: italic; color: #003366; }
.reskar {font-size: 12px; font-style: italic; color: #333333; font-family: Calibri;}
-->
</style>
<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td colspan="2"><div id="gennn" style="width:100%; height:300; overflow:auto;">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#333333" bgcolor="#CCCCCC">
            <tr>
              <td width="100" align="left"><span class="titubuskar0">N°Pago</span></td>
              <td width="150" align="left"><span class="titubuskar0">Concepto</span></td>
              <td width="100" align="left"><span class="titubuskar0">Tipo</span></td>
              <td width="70" align="left"><span class="titubuskar0">Serie</span></td>
              <td width="120" align="left"><span class="titubuskar0">Documento</span></td>
              <td width="120" align="left"><span class="titubuskar0">Fec.Pago</span></td>
              <td width="120" align="left"><span class="titubuskar0">Imp.Pago</span></td>
              <td width="100" align="left"><span class="titubuskar0">Estado</span></td>
              <td width="55"  align="right"><span class="titubuskar0"></span></td>
            </tr>
          </table></td>
        </tr>
        <tr>
          <td><div id="bkardex">
            <?php 
include("../../conexion.php");

// ACTUALIZACIÓN: Deben aparecer TODOS los documentos
// Se elimininó:  WHERE m_regpagos.swt_est NOT IN('A','T')  (30/06/2013)

if($evalbus=='0')           ## POR DEFECTO
{ 
$consulkar = mysql_query("SELECT m_regpagos.num_vouc AS 'id', m_cteventas.concepto AS 'concepto', tip_documen.des_docum AS 'tipo', m_regpagos.serie AS 'serie', 
m_regpagos.numero AS 'documento', DATE_FORMAT(m_regpagos.fec_pago,'%d/%m/%Y') AS 'fecha', m_regpagos.imp_pago AS 'importe',
(CASE WHEN m_regpagos.swt_est='' THEN 'ACTIVO'  ELSE 'ANULADO' END) AS 'estado'
FROM m_regpagos
INNER JOIN tip_documen ON tip_documen.id_documen = m_regpagos.tipo_docu
INNER JOIN m_cteventas ON m_cteventas.num_docu_cli = m_regpagos.num_doc_cli AND m_cteventas.tipo_docu = m_regpagos.tipo_docu 
AND m_cteventas.serie = m_regpagos.serie AND m_cteventas.documento = m_regpagos.numero ORDER BY m_regpagos.fec_pago DESC ", $conn) or die(mysql_error());



}
else if($evalbus=='2')      ## POR ID DEL CLIENTE
{ 
$consulkar = mysql_query("SELECT m_regpagos.num_vouc AS 'id', m_cteventas.concepto AS 'concepto', tip_documen.des_docum AS 'tipo', m_regpagos.serie AS 'serie', 
m_regpagos.numero AS 'documento', DATE_FORMAT(m_regpagos.fec_pago,'%d/%m/%Y') AS 'fecha', m_regpagos.imp_pago AS 'importe',
(CASE WHEN m_regpagos.swt_est='' THEN 'ACTIVO'  ELSE 'ANULADO' END) AS 'estado'
FROM m_regpagos
INNER JOIN tip_documen ON tip_documen.id_documen = m_regpagos.tipo_docu
INNER JOIN m_cteventas ON m_cteventas.num_docu_cli = m_regpagos.num_doc_cli AND m_cteventas.tipo_docu = m_regpagos.tipo_docu 
AND m_cteventas.serie = m_regpagos.serie AND m_cteventas.documento = m_regpagos.numero
WHERE m_regpagos.num_doc_cli = '$codigo_cli' ORDER BY m_regpagos.fec_pago DESC ", $conn) or die(mysql_error());
}
else if($evalbus=='1')      ## POR NUMERO DE DOCUMENTO
{
$consulkar = mysql_query("SELECT m_regpagos.num_vouc AS 'id', m_cteventas.concepto AS 'concepto', tip_documen.des_docum AS 'tipo', m_regpagos.serie AS 'serie', 
m_regpagos.numero AS 'documento', DATE_FORMAT(m_regpagos.fec_pago,'%d/%m/%Y') AS 'fecha', m_regpagos.imp_pago AS 'importe',
(CASE WHEN m_regpagos.swt_est='' THEN 'ACTIVO'  ELSE 'ANULADO' END) AS 'estado'
FROM m_regpagos
INNER JOIN tip_documen ON tip_documen.id_documen = m_regpagos.tipo_docu
INNER JOIN m_cteventas ON m_cteventas.num_docu_cli = m_regpagos.num_doc_cli AND m_cteventas.tipo_docu = m_regpagos.tipo_docu 
AND m_cteventas.serie = m_regpagos.serie AND m_cteventas.documento = m_regpagos.numero
WHERE m_regpagos.tipo_docu = '$tipo_docu' AND m_regpagos.serie = '$serie' AND m_regpagos.numero = '$documento' ORDER BY m_regpagos.fec_pago DESC ", $conn) or die(mysql_error());		
}

while($rowkar = mysql_fetch_array($consulkar)){

echo "<table width='100%' border='1' cellpadding='0' cellspacing='0' bordercolor='#333333' >
  <tr>
    <td width='100' style=max-width:90px;min-width:90px;' align='left' ><span class='reskar'>".$rowkar['id']."</span></td>
	<td width='130' style=max-width:150px;min-width:130px;' align='left' ><span class='reskar'>".str_replace("*","&",str_replace("?","'",strtoupper(utf8_decode($rowkar['concepto']))))."</span></td>
	<td width='100' style=max-width:100px; min-width:100px;' align='left' ><span class='reskar'>".$rowkar['tipo']."</span></td>
	<td width='70' style=max-width:70px; min-width:70px;' align='left' ><span class='reskar'>".$rowkar['serie']."</span></td>
	<td width='120' style=max-width:120px; min-width:120px;' align='left' ><span class='reskar'>".$rowkar['documento']."</span></td>
	<td width='120' style=max-width:120px; min-width:120px;' align='left' ><span class='reskar'>".$rowkar['fecha']."</span></td>
	<td width='120' style=max-width:120px; min-width:120px;' align='right' ><span class='reskar'>".$rowkar['importe']."</span></td>
	<td width='100' style=max-width:100px; min-width:100px;' align='center' ><span class='reskar'>";
	
	if($rowkar['estado']=='')
	  {
		echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";			
	  } 
	 else {
		echo $rowkar['estado'];						
		  };

echo "</span></td>
	
	<td width='50' style=max-width:50px; min-width:50px;' align='center' >";
	
	 if($rowkar['estado']=='ACTIVO')
	  {
		echo "<a href='#' id='".$rowkar['id']."' name='".$rowkar['id']."' onclick='ElimPago(this.id)'><img src='../../images/delete.png' width='16' height='18'></a>";			
	  } 
	 else {
			echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";						
		  };
											  
echo "</td>
  </tr>
</table>";
}
?>
          </div></td>
        </tr>
      </table>
    </div></td>
  </tr>
</table>



